package ru.papergames.web.blines.battle.network.serverpackets;

import java.nio.ByteBuffer;

/**
 * TODO: add description
 *
 * @author Alexander Troshanin
 */
public class CompositeBuffer {

    private int packetId;
    private ByteBuffer buffer;
    private int chunksSize;
    private int receivedChunksCount;

    public CompositeBuffer(int packetId, ByteBuffer buffer, int chunksSize) {
        this.packetId = packetId;
        this.buffer = buffer;
        this.chunksSize = chunksSize;
        receivedChunksCount = 0;
    }

    public int getPacketId() {
        return packetId;
    }

    public ByteBuffer getBuffer() {
        return buffer;
    }

    public void addChunk(byte [] chunk, int offset) {
        buffer.put(chunk, offset, chunk.length);
        receivedChunksCount++;
    }

    public boolean isReady() {
        return receivedChunksCount == chunksSize;
    }

}
